package com.learn.micro_mall.domain.service.goods;

import com.learn.micro_mall.domain.entity.brand.BrandEntity;
import com.learn.micro_mall.domain.entity.category.CategoryEntity;
import com.learn.micro_mall.domain.entity.goods.GoodsEntity;
import com.learn.micro_mall.domain.vo.category.CategoryId;
import com.learn.micro_mall.repository.brand.BrandRepository;
import com.learn.micro_mall.repository.category.CategoryRepository;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

@Service
public class GoodsValidatorDomainService {

    @Resource
    private BrandRepository brandRepository;
    @Resource
    private CategoryRepository categoryRepository;

    public void validGoods(GoodsEntity goodsEntity) throws Exception {
        if(goodsEntity.getBrandName() != null) {
            BrandEntity brandEntity = brandRepository.getBrandEntityByBrandName(goodsEntity.getBrandName());
            if (brandEntity == null) {
                throw new Exception("不存在该品牌");
            }
        }
        if(goodsEntity.getGoodsCategoryVO().getCategoryId() != null){
//            CategoryId categoryId = CategoryId.builder().categoryId(goodsEntity.getGoodsCategoryVO().getCategoryId()).build();
//            CategoryEntity categoryEntity = categoryRepository.getByCategoryId(categoryId);
//            if(categoryEntity == null){
//                throw new Exception("不存在该商品分类");
//            }
        }
    }
}
